home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol05 / 02 / clipbrd / owner2.c < prev    next >
Text File  |  1990-03-01  |  10KB  |  358 lines

  1. /*
  2.  * WINDOWS CLIPBOARD VIEWER - OWNER DISPLAY FORMAT SOURCE CODE
  3.  *
  4.  * LANGUAGE      : Microsoft C5.1
  5.  * MODEL         : small
  6.  * ENVIRONMENT   : Microsoft Windows 2.1 SDK
  7.  * STATUS        : operational
  8.  *
  9.  * Kevin P. Welch
  10.  */
  11.  
  12. #define  NOCOMM
  13. #include <windows.h>
  14.  
  15. BOOL PASCAL        OwnerInit( HANDLE, WORD, WORD, LPSTR );
  16.  
  17. HANDLE FAR PASCAL    OwnerCreate( HWND, HANDLE );
  18. HANDLE FAR PASCAL    OwnerSize( HWND, HANDLE, WORD, LONG );
  19. HANDLE FAR PASCAL    OwnerHScroll( HWND, HANDLE, WORD, LONG );
  20. HANDLE FAR PASCAL    OwnerVScroll( HWND, HANDLE, WORD, LONG );
  21. HANDLE FAR PASCAL    OwnerPaint( HWND, HANDLE, WORD, LONG );
  22. HANDLE FAR PASCAL    OwnerDestroy( HWND, HANDLE );
  23.  
  24. /* BOOL
  25.  * OwnerInit( hInstance, wDataSegment, wHeapSize, lpszCmdLine )
  26.  *
  27.  *    hInstance      library instance handle
  28.  *    wDataSegment   library data segment
  29.  *    wHeapSize      default heap size
  30.  *    lpszCmdLine    command line arguments
  31.  *
  32.  * This function performs all the initialization necessary to use
  33.  * the owner display dynamic library.  It is assumed that no local
  34.  * heap is used, hence no call to LocalInit.  A non-zero value is
  35.  * returned if the initialization was sucessful.
  36.  *
  37.  */
  38.  
  39. BOOL PASCAL OwnerInit( hInstance,wDataSegment,wHeapSize,lpszCmdLine )
  40.    HANDLE      hInstance;
  41.    WORD        wDataSegment;
  42.    WORD        wHeapSize;
  43.    LPSTR       lpszCmdLine;
  44. {
  45.  
  46.  /* warning level 3 compatibility */
  47.  hInstance;
  48.  wDataSegment;
  49.  wHeapSize;
  50.  lpszCmdLine;
  51.  
  52.  /* sucessful return */
  53.    return( TRUE );
  54.  
  55. }
  56.  
  57. /*
  58.  * OwnerCreate( hWnd, hClipData ) : HANDLE;
  59.  *
  60.  *    hWnd           handle to display window
  61.  *    hClipData      handle to current clipboard data
  62.  *
  63.  * This function performs all the initialization necessary in order
  64.  * to view an owner display clipboard format.  A handle to a display
  65.  * information data block (the internal format of which is only known
  66.  * inside this module) is returned which the owner is responsible
  67.  * for saving.  In the owner display case the handle to the current
  68.  * clipboard data is sufficient information to maintain the display.
  69.  */
  70.  
  71. HANDLE FAR PASCAL OwnerCreate(
  72.  HWND      hWnd,
  73.  HANDLE    hClipData )
  74. {
  75.  HANDLE    hRect;
  76.  LPRECT    lpRect;
  77.  HWND      hWndOwner;
  78.  
  79.  /* reset scroll bars */
  80.  SetScrollPos( hWnd, SB_HORZ, 0, TRUE );
  81.  SetScrollPos( hWnd, SB_VERT, 0, TRUE );
  82.  
  83.  /* notify clipboard owner of change */
  84.  hWndOwner = GetClipboardOwner();
  85.  if ( hWndOwner ) {
  86.  
  87.    /* allocate space for update rectangle */
  88.    hRect = GlobalAlloc( GHND, (DWORD)sizeof(RECT) );
  89.    if ( hRect ) {
  90.  
  91.      /* lock update rectangle */
  92.      lpRect = (LPRECT)GlobalLock( hRect );
  93.      if ( lpRect ) {
  94.  
  95.        /* define the update rectangle & notify clipboard owner */
  96.        GetClientRect( hWnd, lpRect );
  97.        SendMessage( hWndOwner, WM_SIZECLIPBOARD, hWnd,
  98.                     MAKELONG(hRect,0) );
  99.  
  100.        /* unlock the rectangle */
  101.        GlobalUnlock( hRect );
  102.  
  103.      }
  104.  
  105.      /* release the rectangle */
  106.      GlobalFree( hRect );
  107.  
  108.    }
  109.  
  110.  }
  111.  
  112.  /* return clipboard data handle */
  113.  return( hClipData );
  114.  
  115. }
  116.  
  117. /*
  118.  * OwnerSize( hWnd, hDispInfo, wParam, lParam ) : HANDLE;
  119.  *
  120.  *   hWnd        handle to display window
  121.  *   hDispInfo   handle to display information block
  122.  *   wParam      word parameter of WM_SIZE message
  123.  *   lParam      long parameter of WM_SIZE message
  124.  *
  125.  * This function resets the display information data block whenever
  126.  * the size of the display region is changed.  If successful, a
  127.  * handle to the new display information data block is returned.
  128.  * Failure to call this function whenever the size of the display
  129.  * region is changed will cause unusual display results.
  130.  */
  131.  
  132. HANDLE FAR PASCAL OwnerSize(
  133.  HWND      hWnd,
  134.  HANDLE    hDispInfo,
  135.  WORD      wParam,
  136.  LONG      lParam )
  137. {
  138.  HANDLE    hRect;
  139.  LPRECT    lpRect;
  140.  HWND      hWndOwner;
  141.  
  142.  /* warning level 3 compatibility */
  143.  wParam;
  144.  
  145.  /* reset scroll bars */
  146.  SetScrollPos( hWnd, SB_HORZ, 0, TRUE );
  147.  SetScrollPos( hWnd, SB_VERT, 0, TRUE );
  148.  
  149.  /* notify clipboard owner of change */
  150.  hWndOwner = GetClipboardOwner();
  151.  if ( hWndOwner ) {
  152.  
  153.    /* allocate space for update rectangle */
  154.    hRect = GlobalAlloc( GHND, (DWORD)sizeof(RECT) );
  155.    if ( hRect ) {
  156.  
  157.      /* lock update rectangle */
  158.      lpRect = (LPRECT)GlobalLock( hRect );
  159.      if ( lpRect ) {
  160.  
  161.        /* define the update rectangle */
  162.        lpRect->top = 0;
  163.        lpRect->left = 0;
  164.        lpRect->right = LOWORD(lParam);
  165.        lpRect->bottom = HIWORD(lParam);
  166.  
  167.        /* notify the clipboard owner */
  168.        SendMessage( hWndOwner, WM_SIZECLIPBOARD, hWnd,
  169.                     MAKELONG(hRect,0) );
  170.  
  171.        /* unlock the rectangle */
  172.        GlobalUnlock( hRect );
  173.  
  174.      }
  175.  
  176.      /* release the rectangle */
  177.      GlobalFree( hRect );
  178.  
  179.    }
  180.  
  181.  }
  182.  
  183.  /* return final result */
  184.  return( hDispInfo );
  185.  
  186. }
  187.  
  188. /*
  189.  * OwnerHScroll( hWnd, hDispInfo, wParam, lParam ) : HANDLE;
  190.  *
  191.  *   hWnd        handle to display window
  192.  *   hDispInfo   handle to display information block
  193.  *   wParam      word parameter of WM_HSCROLL message
  194.  *   lParam      long parameter of WM_HSCROLL message
  195.  *
  196.  * This function is responsible for handling all the horizontal
  197.  * scroll messages received when viewing a bitmap clipboard format.
  198.  * If necessary, changes to the display info block can be made.
  199.  * As currently implemented, no action is taken.  The value returned
  200.  * is the handle to the updated display information block.
  201.  */
  202.  
  203. HANDLE FAR PASCAL OwnerHScroll(
  204.  HWND      hWnd,
  205.  HANDLE    hDispInfo,
  206.  WORD      wParam,
  207.  LONG      lParam )
  208. {
  209.  HWND      hWndOwner;
  210.  
  211.  /* notify clipboard owner if present */
  212.  hWndOwner = GetClipboardOwner();
  213.  if ( hWndOwner )
  214.    SendMessage( hWndOwner, WM_HSCROLLCLIPBOARD, hWnd,
  215.                 MAKELONG(wParam,LOWORD(lParam)) );
  216.  
  217.  /* return result */
  218.  return( hDispInfo );
  219.  
  220. }
  221.  
  222. /*
  223.  * OwnerVScroll( hWnd, hDispInfo, wParam, lParam ) : HANDLE;
  224.  *
  225.  *   hWnd        handle to display window
  226.  *   hDispInfo   handle to display information block
  227.  *   wParam      word parameter of WM_VSCROLL message
  228.  *   lParam      long parameter of WM_VSCROLL message
  229.  *
  230.  * This function is responsible for handling all the vertical scroll
  231.  * messages received when viewing a bitmap clipboard format.  If
  232.  * necessary, changes to the display info block can be made.
  233.  * As currently implemented, no action is taken.  The value returned
  234.  * is the handle to the updated display information block.
  235.  */
  236.  
  237. HANDLE FAR PASCAL OwnerVScroll(
  238.  HWND      hWnd,
  239.  HANDLE    hDispInfo,
  240.  WORD      wParam,
  241.  LONG      lParam )
  242. {
  243.  HWND      hWndOwner;
  244.  
  245.  /* notify clipboard owner if present */
  246.  hWndOwner = GetClipboardOwner();
  247.  if ( hWndOwner )
  248.    SendMessage( hWndOwner, WM_VSCROLLCLIPBOARD, hWnd,
  249.                 MAKELONG(wParam,LOWORD(lParam)) );
  250.  
  251.  /* return result */
  252.  return( hDispInfo );
  253.  
  254. }
  255.  
  256. /*
  257.  * OwnerPaint( hWnd, hDispInfo, wParam, lParam ) : HANDLE;
  258.  *
  259.  *   hWnd        handle to display window
  260.  *   hDispInfo   handle to display information block
  261.  *   wParam      word parameter of WM_PAINT message
  262.  *   lParam      long parameter of WM_PAINT message
  263.  *
  264.  * This function is responsible for handling all the paint related
  265.  * aspects for the bitmap clipboard format.  This function calculates
  266.  * the required update portion of the window and BitBlts the bitmap
  267.  * into the region.  The handle returned by this function is to the
  268.  * update display information block.
  269.  */
  270.  
  271. HANDLE FAR PASCAL OwnerPaint(
  272.  HWND          hWnd,
  273.  HANDLE        hDispInfo,
  274.  WORD          wParam,
  275.  LONG          lParam )
  276. {
  277.  HANDLE        hPs;
  278.  LPPAINTSTRUCT lpPs;
  279.  HWND          hWndOwner;
  280.  
  281.  /* warning level 3 compatibility */
  282.  wParam;
  283.  lParam;
  284.  
  285.  /* allocate space for paint structure */
  286.  hPs = GlobalAlloc( GHND, (DWORD)sizeof(PAINTSTRUCT) );
  287.  if ( hPs ) {
  288.  
  289.    /* lock it down */
  290.    lpPs = (LPPAINTSTRUCT)GlobalLock( hPs );
  291.    if ( lpPs ) {
  292.  
  293.      /* start the paint operation */
  294.      BeginPaint( hWnd, lpPs );
  295.  
  296.      /* notify the clipboard owner if present */
  297.      hWndOwner = GetClipboardOwner();
  298.      if ( hWndOwner )
  299.        SendMessage( hWndOwner, WM_PAINTCLIPBOARD, hWnd,
  300.                     MAKELONG(hPs,0) );
  301.  
  302.      /* end the paint operation & unlock the paint structure */
  303.      EndPaint( hWnd, lpPs );
  304.      GlobalUnlock( hPs );
  305.  
  306.    }
  307.  
  308.    /* release the paint structure */
  309.    GlobalFree( hPs );
  310.  
  311.  }
  312.  
  313.  /* return final result */
  314.  return( hDispInfo );
  315.  
  316. }
  317.  
  318. /*
  319.  * OwnerDestroy( hDispInfo ) : HANDLE;
  320.  *
  321.  *   hWnd        handle to display window
  322.  *   hDispInfo   handle to display information block
  323.  *
  324.  * This function is to be called whenever the display region is being
  325.  * destroyed.  It is responsible for restoring the system to it's
  326.  * original state and for releasing any memory or resources defined.
  327.  * The value returned is the handle to the OLD display information
  328.  * block.  This handle should NEVER be used after this function is
  329.  * called.  If an error occurs a value of NULL is returned.
  330.  *
  331.  * Note that is this function we are passing a NULL rectangle to the
  332.  * clipboard owner.  This informs it that it can release any/all
  333.  * resources used to support the display of Owner Display data.
  334.  */
  335.  
  336. HANDLE FAR PASCAL OwnerDestroy(
  337.  HWND      hWnd,
  338.  HANDLE    hDispInfo )
  339. {
  340.  HANDLE    hRect;
  341.  HWND      hWndOwner;
  342.  
  343.  /* check if clipboard owner still around */
  344.  hWndOwner = GetClipboardOwner();
  345.  if ( hWndOwner ) {
  346.  
  347.    /* notify clipboard owner */
  348.    hRect = GlobalAlloc( GHND, (DWORD)sizeof(RECT) );
  349.    SendMessage(hWndOwner,WM_SIZECLIPBOARD,hWnd,MAKELONG(hRect,0) );
  350.    GlobalFree( hRect );
  351.  
  352.  }
  353.  
  354.  /* return old handle */
  355.  return( hDispInfo );
  356.  
  357. }
  358.